package com.qf.controller;

import com.qf.pojo.req.XcUserReq;
import com.qf.pojo.resp.BaseResp;
import com.qf.service.PersonalService;
import com.qf.utils.UploadUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;


@Api(value = "个人中心接口",tags = "个人中心接口")
@RestController
@RequestMapping("/personal")
public class PersonalController {

    @Autowired
    PersonalService personalService;

    @Autowired
    UploadUtils uploadUtils;

    //查询用户信息 发起该页面请求时需要默认加载
    @ApiOperation("查询用户信息 发起该页面请求时需要默认加载")
    @RequestMapping(value = "/select",method = RequestMethod.GET)
    public BaseResp select(HttpServletRequest request){

        return personalService.select(request);
    }

    //修改用户信息
    @ApiOperation("修改用户信息")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public BaseResp update(@RequestBody XcUserReq xcUserReq, HttpServletRequest request){
        return personalService.update(xcUserReq,request);
    }

    //修改密码（用老密码修改）
    @ApiOperation("修改密码,可以检测旧密码是否正确")
    @RequestMapping(value = "/updatepasswordbyoldpasswode",method = RequestMethod.POST)
    public BaseResp updatepasswordbyoldpasswode(HttpServletRequest request, @RequestBody XcUserReq xcUserReq){

        return personalService.updatepasswordbyoldpasswode(request,xcUserReq);
    }

    //上传头像
    @ApiOperation("修改头像")
    @RequestMapping(value = "upload",method = RequestMethod.POST)
    public BaseResp upload(@RequestParam("file") MultipartFile multipartFilet, HttpServletRequest request){
       return personalService.upload(multipartFilet,request);
    }

    @ApiOperation("查看头像接口,显示修改前和修改后的头像展示")
    @RequestMapping(value = "/findpic",method = RequestMethod.GET)
    public BaseResp findpic(HttpServletRequest request){

        return personalService.findpic(request);
    }

}
